import { useUserStore } from '@/store';
import { Navigate, Outlet, useLocation } from 'react-router-dom';

export const PrivateRoute = ({ children }: { children: React.ReactNode }) => {
	const user = useUserStore.getState().user;
	const location = useLocation();

	if (!user) {
		return <Navigate to="/login" replace state={{ from: location }} />;
	}
	return <>{children}</>;
};

export const NavigateRoute = () => {
	const user = useUserStore.getState().user;
	return user ? <Navigate to="/myStudy" replace /> : <Outlet />;
};
